package spring.yongongsystem.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import spring.yongongsystem.POJO.dto.ProductPageQueryDTO;
import spring.yongongsystem.POJO.entity.Product;

@Mapper
public interface ProductMapper{

    @Insert("insert into product(name, description, price, category_id,photo)" +
            " VALUES" +
            " (#{name},#{description},#{price},#{categoryId},#{photo})")
    void insert(Product product);
    @Select("select count(id) from unloading.product where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 根据id删除产品
     * @param id
     */
    @Delete("delete from unloading.product where id = #{id}")
    void deleteById(Long id);

    /**
     * 产品分页查询
     *
     * @param productPageQueryDTO
     * @return
     */
    Page<Product> pageQuery(ProductPageQueryDTO productPageQueryDTO);

    void update(Product product);

    @Select("SELECT COUNT(*) FROM product;")
    long count();
}